<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('title','订单详情');
if($_RQ['op']=='main'){
	//返回链接
	$return['forward_url']=base64_encode('jy_qiuyuyue/manage.order//fromcreate=1');
	$isfollow=pdo_getcolumn('core_fans',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'follow');
	if($_RQ['id']){
		$id = intval($_RQ['id']);
		$order=pdo_get('jy_qiuyuyue_server_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>intval($_RQ['id'])));
	}elseif($_RQ['ordersn']){
		$order=pdo_get('jy_qiuyuyue_server_order',array('uniacid'=>$_SESSION['uniacid'],'ordersn'=>trim($_RQ['ordersn'])));
	}
	if(!$order){
		exi('指定订单不存在！','error','goback');
	}
	if($order['status']==0){
		$order['fromseconds']=time()-$order['createtime'];
		$order['outseconds']=$shopset['orderpay_outtime']*3600;
		if($order['fromseconds']<$order['outseconds']){
			$order['fromseconds']=($order['fromseconds']/$order['outseconds'])*428;
			$order['upseconds']=$this->model()->date($order['outseconds']-$order['fromseconds']);
		}else{
			$order['upseconds']=0;
		}
	}
	//定义订单状态名称
	if($order['status']==0 && $order['paytype']!=3){
		$order['statustitle']='订单待支付';
		$order['statusdesc']='超时未支付，订单将自动取消';
	}elseif($order['status']==0 && $order['paytype']==3){
		$order['statustitle']='货到付款';
		$order['statusdesc']='请您收到商品后付款';
	}elseif($order['status']==1 && !$order['refundstate']){
		$order['statustitle']='买家已付款';
		$order['statusdesc']='请您留意订单进度';
	}elseif($order['status']==2 && !$order['refundstate']){
		$order['statustitle']='商家已发货';
		$order['statusdesc']='请您留意订单进度';
	}elseif($order['status']==3 && !$order['refundstate']){
		$order['statustitle']='订单已完成';
		$order['statusdesc']='';
	}elseif($order['status']==4 && !$order['refundstate']){
		$order['statustitle']='订单已关闭';
		$order['statusdesc']='';
	}elseif($order['refundstate']>0 && $order['status']==1){
		$order['statustitle']='申请退款中';
		$order['statusdesc']='请您留意退款进度';
	}elseif($order['refundstate']>0 && $order['status']>1){
		$order['statustitle']='申请售后中';
		$order['statusdesc']='请您留意售后进度';
	}
	//包含核销商品
	if($order['status']==2 && $order['isverify']==1){
		$order['statustitle']='部分商品已发货';
		$order['statusdesc']='除核销商品，其他商品已发货';
	}elseif($order['status']==2 && $order['isverify']==2){
		$order['statustitle']='等待核销';
		$order['statusdesc']='属核销商品，请核销！';
	}elseif($order['status']==3 && $order['isverify']==2){
		$order['statustitle']='已核销';
		$order['statusdesc']='属核销商品，已核销完成！';
	}
	//时间格式化
	$order['worker_name']=pdo_getcolumn('jy_qiuyuyue_store_worker',array('id'=>$order['worker_id'],'uniacid'=>$_SESSION['uniacid']),'name');
	$order['serve']=pdo_get('jy_qiuyuyue_serve',array('id'=>$order['serve_id'],'uniacid'=>$_SESSION['uniacid']),array('title','serve_time','image'));
	$package=json_decode($order['package'],true);
	$order['package']=$package['package_title'];
	$serve_time=$order['serve']['serve_time'];
	$serve_time=json_decode($serve_time,true);
	$timeids=str_array($order['timeid']);
	$serve_times=array();
	$totalprice=0;
	foreach($timeids as $tv){
				$fee=$serve_time[intval($tv)]['fee']?:$serve['price'];
				if($order['is_ban']){
					$fee=50*$fee/100;
				}
				$serve_time[intval($tv)]['fee']=$fee;
				$serve_times[]=$serve_time[intval($tv)];
	}
	$order['serve_times']=$serve_times;
	$order['createtime']=date('Y-m-d H:m:s',$order['createtime']);
	$order['paytime']=date('Y-m-d H:i:s',$order['paytime']);
	$order['sendtime']=$order['express']['createtime']?date('Y-m-d H:i:s',$order['express']['createtime']):'';
	$order['finishtime']=date('Y-m-d H:i:s',$order['finishtime']);
	if ($order['userdeleted'] == 2) {
			exi('订单已经被删除!','error');
	}
	$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['mid']));                       //用户信息
	if (!empty($order['diyformfields']) && !empty($order['diyformdata'])) {
		$order_fields = $order['diyformfields'];
		$order_data = $order['diyformdata'];
	}
	if($order['sendtype']==3 && $order['status']==3){
		$order['content']=$this->pdo_getcolumn('order_virtual',array('orderid'=>$order['id']),'content');
	}
	$order['plate']=pdo_get('jy_qiuyuyue_serve_plate',array('id'=>intval($order['plate_id']),'uniacid'=>$_SESSION['uniacid']),array('title'));
	$return['order']=$order;
	$return['member']=$member;
	$return['order_fields']=$order_fields;
	$return['order_data']=$order_data;
	exi($return);
}
//删除订单
if($_RQ['op']=='delete'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$this->model('order')->order_delete($_RQ['id'],true);
	exi('已删除订单!');
}
//恢复订单
if($_RQ['op']=='reset'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$this->model('order')->order_reset($_RQ['id'],true);
	exi('已恢复订单!');
}
//彻底删除订单
if($_RQ['op']=='rdelete'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$this->model('order')->order_rdelete($_RQ['id']);
	exi('已彻底删除订单!');
}
//取消订单
if($_RQ['op']=='cancel'){
	$id=intval($_RQ['id']);
	if($id){
		$this->model('order')->order_cancel($id);
		exi('取消成功！','','order.list/');		
	}else{		
		exi('取消失败！','error');
	}
}
//确认订单
if($_RQ['op']=='confirm'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$update=array('status'=>'3');
	pdo_update('jy_weishop_order',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('已确认收货!');
}
//支付订单
if($_RQ['op']=='setpay'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$pay_id=pdo_getcolumn('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'pay_id');
	exi($pay_id);
}
//确认订单
if($_RQ['op']=='hexiao'){
	if(!$_RQ['ordersn']){
		exi('订单不存在，请重新选择订单','error');
	}
	$update=array('status'=>'2');
	pdo_update('jy_weishop_order',$update,array('uniacid'=>$_SESSION['uniacid'],'ordersn'=>$_RQ['ordersn']));
	exi('已确认用户进场!');
}
?>